{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['celeba_dcgan', 'celeba_lsgan', 'celeba_wgan', 'celeba_wgan_gp', 'progressGAN']\n",
      "Processing dir celeba_dcgan\n",
      "Processing dir celeba_lsgan\n",
      "Processing dir celeba_wgan\n",
      "Processing dir progressGAN\n",
      "Found 746270 fake images and 202599 real images\n",
      "Processing dir celeba_wgan_gp\n",
      "Overlapping between train and validation elements:\n",
      " set()\n",
      "Overlapping between train and test elements:\n",
      " set()\n",
      "Processing dir celeba_dcgan\n",
      "Processing dir celeba_lsgan\n",
      "Processing dir celeba_wgan\n",
      "Processing dir celeba_wgan_gp\n",
      "Found 728360 fake images and 202599 real images\n",
      "Processing dir progressGAN\n",
      "Overlapping between train and validation elements:\n",
      " set()\n",
      "Overlapping between train and test elements:\n",
      " set()\n",
      "Processing dir celeba_dcgan\n",
      "Processing dir celeba_lsgan\n",
      "Processing dir celeba_wgan_gp\n",
      "Processing dir progressGAN\n",
      "Found 746270 fake images and 202599 real images\n",
      "Processing dir celeba_wgan\n",
      "Overlapping between train and validation elements:\n",
      " set()\n",
      "Overlapping between train and test elements:\n",
      " set()\n",
      "Processing dir celeba_lsgan\n",
      "Processing dir celeba_wgan\n",
      "Processing dir celeba_wgan_gp\n",
      "Processing dir progressGAN\n",
      "Found 746270 fake images and 202599 real images\n",
      "Processing dir celeba_dcgan\n",
      "Overlapping between train and validation elements:\n",
      " set()\n",
      "Overlapping between train and test elements:\n",
      " set()\n",
      "Processing dir celeba_dcgan\n",
      "Processing dir celeba_wgan\n",
      "Processing dir celeba_wgan_gp\n",
      "Processing dir progressGAN\n",
      "Found 746270 fake images and 202599 real images\n",
      "Processing dir celeba_lsgan\n",
      "Overlapping between train and validation elements:\n",
      " set()\n",
      "Overlapping between train and test elements:\n",
      " set()\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import os\n",
    "import cv2\n",
    "import numpy as np\n",
    "import random as rn\n",
    "import threading\n",
    "import time\n",
    "import signal\n",
    "import sys\n",
    "import pdb\n",
    "\n",
    "\n",
    "fn='data/celebA'\n",
    "myfiles = os.listdir(fn)\n",
    "glen1 = len(myfiles)\n",
    "real_content = []\n",
    "\n",
    "for i in range(glen1):\n",
    "    real_content.append('%s/%s' % (fn,  myfiles[i]))\n",
    "\n",
    "fn='results'\n",
    "subdirs = os.listdir(fn)\n",
    "dir_num = len(subdirs)\n",
    "print(subdirs)\n",
    "exclusive_list = ['celeba_wgan_gp', 'progressGAN', 'celeba_wgan', 'celeba_dcgan', 'celeba_lsgan']\n",
    "\n",
    "split_num = len(exclusive_list)\n",
    "\n",
    "for ext_num in range(split_num):\n",
    "    \n",
    "    fake_content = []\n",
    "    for i in range(dir_num):\n",
    "        \n",
    "        if exclusive_list[ext_num] != subdirs[i]:\n",
    "            print(\"Processing dir %s\"%(subdirs[i]))\n",
    "            myfiles = os.listdir('%s/%s/' % (fn, subdirs[i]))\n",
    "            files_num = len(myfiles)\n",
    "            for j in range(files_num):\n",
    "                fake_content.append('%s/%s/%s' % (fn, subdirs[i], myfiles[j]))\n",
    "    flen1 = len(fake_content)\n",
    "\n",
    "    seq1 = np.array(range(0,glen1))\n",
    "    rn.shuffle(seq1)\n",
    "    seq2 = np.array(range(0,flen1))\n",
    "    rn.shuffle(seq2)\n",
    "\n",
    "\n",
    "    print('Found %d fake images and %d real images'%(flen1, glen1))\n",
    "    if glen1<flen1:\n",
    "        targetLen = glen1 - 5000 - 5000\n",
    "    else:\n",
    "        targetLen = flen1 - 5000 - 5000\n",
    "    pcnt = 0\n",
    "    cnt = 0\n",
    "\n",
    "    text_file = open(\"data/train_wo_%s.txt\"%(exclusive_list[ext_num]), \"w\")\n",
    "    for i in range(targetLen):\n",
    "        text_file.write('%s 1\\n'%(real_content[seq1[i]]))\n",
    "        text_file.write('%s 0\\n'%(fake_content[seq2[i]]))\n",
    "    text_file.close()\n",
    "\n",
    "    fake_content = []\n",
    "    print(\"Processing dir %s\"%(exclusive_list[ext_num]))\n",
    "    myfiles = os.listdir('%s/%s/' % (fn, exclusive_list[ext_num]))\n",
    "    files_num = len(myfiles)\n",
    "    for j in range(files_num):\n",
    "        fake_content.append('%s/%s/%s' % (fn, exclusive_list[ext_num], myfiles[j]))\n",
    "    flen1 = len(fake_content)\n",
    "    seq2 = np.array(range(0,flen1))\n",
    "    rn.shuffle(seq2)\n",
    "\n",
    "    text_file = open(\"data/val_wo_%s.txt\"%(exclusive_list[ext_num]), \"w\")\n",
    "    for i in range(targetLen, targetLen+5000):\n",
    "        text_file.write('%s 1\\n'%(real_content[seq1[i]]))\n",
    "        text_file.write('%s 0\\n'%(fake_content[seq2[i % flen1]]))\n",
    "    text_file.close()\n",
    "    \n",
    "    text_file = open(\"data/test_wo_%s.txt\"%(exclusive_list[ext_num]), \"w\")\n",
    "    for i in range(targetLen+5000, targetLen+10000):\n",
    "        text_file.write('%s 1\\n'%(real_content[seq1[i]]))\n",
    "        text_file.write('%s 0\\n'%(fake_content[seq2[i % flen1]]))\n",
    "    text_file.close()\n",
    "\n",
    "\n",
    "    ## Check if overlapped\n",
    "    a = open(\"data/train_wo_%s.txt\"%(exclusive_list[ext_num]), \"r\").readlines()\n",
    "    b = open(\"data/val_wo_%s.txt\"%(exclusive_list[ext_num]), \"r\").readlines()\n",
    "    c = open(\"data/test_wo_%s.txt\"%(exclusive_list[ext_num]), \"r\").readlines()\n",
    "    print(\"Overlapping between train and validation elements:\\n\", set(a) & set(b))\n",
    "    print(\"Overlapping between train and test elements:\\n\", set(a) & set(c))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1, 2, 5, 4, 6]\n",
    "b = [9, 8, 7, 6, 5]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
